<?php
namespace offer\action;

use herosphp\bean\Beans;
use herosphp\core\Controller;
use herosphp\core\Loader;
use herosphp\http\HttpRequest;
use api\utils\WeiXinApi;


/**
 * @author yu
 */
class WxInitAction extends CommonAction
{


    public function index(HttpRequest $request)
    {

        $echoStr = $_GET["echostr"];

        $weiXinApi = new WeiXinApi();

        $token = "monda321654987";

        //valid signature , option
        if ($weiXinApi->checkSignature($token)) {
            echo $echoStr;
            exit;
        }

        die;
    }

    public function createMenu(HttpRequest $request)
    {

        $weixin_config = getConfig('weixin_config');


        //获取token
        $weiXinApi = new WeiXinApi();

        $token = $weiXinApi->getAccessToken($weixin_config['appid'], $weixin_config['appser']);

        echo $token;


        //测试删除菜单
        $weiXinApi->delmenu($token);

        $data = '{
           "button":[
           {
                "type":"view",
                 "name":"塑料报价",
                 "url":"http://bj.offer.dasu123.com/mobadmin/offer/add"
            }]
';
        /*
         * ,
            {
                "type":"view",
                 "name":"历史报价单",
                 "url":"http://bj.offer.dasu123.com/mobadmin/offer/index"
             },
             {
                "type":"view",
                 "name":"我的",
                 "url":"http://bj.offer.dasu123.com/mobadmin/index/index"
             }
         */
        //测试创建菜单
        $weiXinApi->creatMenu($token, $data);

       die();
    }


}
